package gemini.castor.ui.client.page.content.home.apply.contractagreement;

import gemini.basic.model.Person;
import gemini.castor.ui.client.utils.GuiUtils;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;

public class ContractAgreementFormView extends Composite implements
		ContractAgreementFormPresenter.Display {

	@UiTemplate("ContractAgreementFormView.ui.xml")
	interface MyUiBinder extends UiBinder<Panel, ContractAgreementFormView> {
	}

	private static final MyUiBinder binder = GWT.create(MyUiBinder.class);

	public ContractAgreementFormView() {
		initWidget(binder.createAndBindUi(this));
	}

	@UiField
	HTML htmContentNameIs;

	@UiField
	HTML htmContentBirthdayIs;

	@UiField
	HTML htmContentIdIs;
	
	@UiField
	HTML htmSpouseFullName;

	@UiField
	HTML htmSpouseBirthday;

	@UiField
	HTML htmSpouseId;
	
	@UiField
	Button btnPrint;
	
	@UiField
	Button btnSubmit;
	
	@UiField
	Button btnBack;

	@UiField
	Button btnCancel;
	
	private List<Person> persons;

	@Override
	public Widget asWidget() {
		return this;
	}

	@Override
	public void loadData() {
		if(persons != null && !persons.isEmpty()){
			htmContentNameIs.setText(persons.get(0).getFirstName() + " " + persons.get(0).getLastName());
			htmContentBirthdayIs.setText(GuiUtils.format(persons.get(0).getDateOfBirth()));
			htmContentIdIs.setText(persons.get(0).getIdentityCard().getNumber());
		
			if(persons.size() > 1){
				htmSpouseFullName.setText(persons.get(1).getFirstName() + " " + persons.get(1).getLastName());
				htmSpouseBirthday.setText(GuiUtils.format(persons.get(1).getDateOfBirth()));
				htmSpouseId.setText(persons.get(1).getIdentityCard().getNumber());
			}
		}
	}
	
	@Override
	public String getFullName(){
		return htmContentNameIs.getHTML();
	}
	
	@Override
	public HasClickHandlers getAgreementSubmitClickHandlers() {
		return btnSubmit;
	}
	
	@Override
	public HasClickHandlers getBackClickHandlers() {
		return btnBack;
	}

	@Override
	public HasClickHandlers getCancelClickHandlers() {
		return btnCancel;
	}

	@Override
	public HasClickHandlers getPrintClickHandlers() {
		return btnPrint;
	}

	@Override
	public void setPersons(List<Person> persons) {
		this.persons = persons;
	}
}
